package com.jiangruan.javaPro.tools;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Security;

/**
 * @author:冷风诉离歌
 * @desc:用于封装各种类型的hash算法
 * @datetime: 2021/12/23 9:22
 */

public class Hash {
    /**
     * @Author: 冷风诉离歌
     * @Description:
     * @Date: 2021/12/23 9:24
     * @Desc:对给定数据进行sha256哈希计算，并返回哈希结果
     * @ReturnType: [byte[]]
     */

    public static byte[] SHA256(byte[] data){
        //message digest,信息摘要
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            digest.update(data);
            return digest.digest();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * @Author: 冷风诉离歌
     * @Description:  
     * @Date: 2021/12/23 20:46
     * @Desc:用于实现RTPEMD160哈希算法，并返回结果
     * @ReturnType: [byte[]]
     */
    
    public static byte[] RipeMD160(byte[] data){
        //provider 提供者
        Security.addProvider(new BouncyCastleProvider());
        try {
            MessageDigest digest = MessageDigest.getInstance("RipeMD160");
            digest.update(data);
            return digest.digest();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
}